package cn.strategy.fund;

import org.junit.Test;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class HuanShouLv_case {

    /**
     * 找到今天换手率大于昨天的股票
     * */
    @Test
    public void show_hsl() throws SQLException, ClassNotFoundException {

        String begin = "2025-05-30";
        String end = "2025-06-03";

        Class.forName("org.h2.Driver");
        Connection conn = DriverManager.getConnection("jdbc:h2:~/data;AUTO_SERVER=TRUE", "root", "root");

        String sql = "SELECT symbol, name FROM type_stock GROUP BY symbol";
        PreparedStatement stmt = conn.prepareStatement(sql);
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            getHuanShouLv(rs.getString(1), begin, end, conn, rs.getString(2));
        }

        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (conn != null) conn.close();
    }

    public void getHuanShouLv(String symbol, String begin, String end, Connection conn, String name) throws SQLException {
        String sql = "SELECT ZHENGFU, HUANSHOULV, ZHANGDIE FROM df_stock_date WHERE SYMBOL = '"+ symbol +"' and STOCK_DATE BETWEEN '"+ begin +"' AND '"+ end +"' ORDER BY STOCK_DATE DESC";
        PreparedStatement stmt = conn.prepareStatement(sql);
        ResultSet rs = stmt.executeQuery();

        List<List<Double>> lst = new ArrayList<>();
        while (rs.next()) {
            //getData_ex(conn, rs.getString(1));
            List<Double> r = new ArrayList<>();
            r.add(rs.getDouble(2));
            r.add(rs.getDouble(3));
            lst.add(r);
        }

        if (lst.size() == 2) {
            if (lst.get(1).get(0) / lst.get(0).get(0) > 2D && lst.get(0).get(1) > 0D && lst.get(1).get(1) < -3D) {
                System.out.println(name);
            }
        }

        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
    }
}
